package com.it.commicity.utils;

import com.fasterxml.uuid.EthernetAddress;
import com.fasterxml.uuid.Generators;
import com.fasterxml.uuid.impl.TimeBasedGenerator;
import org.springframework.stereotype.Component;

import java.util.UUID;

@Component
public class UUIDUtil {

    /**
     * 生成唯一Id
     *
     * @return
     */
    public String getId() {
        //传入网卡信息，基于时间制作出生成器 生成uuid
        TimeBasedGenerator generator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
        UUID uuid = generator.generate();
        String id = uuid.toString().replaceAll("-", "");
        System.out.println("id = " + id);
        return id;
    }

    /**
     * 生成小区编码
     *
     * @return
     */
    public String getCommunityCode() {
        //传入网卡信息，基于时间制作出生成器 生成uuid
        TimeBasedGenerator generator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
        UUID uuid = generator.generate();
        String communityCode = "COMMUNITY_" + uuid.toString().replaceAll("-", "");
        System.out.println("communityCode = " + communityCode);
        return communityCode;
    }

    /**
     * 生成房间编码
     *
     * @return
     */
    public String getRoomCode() {
        //传入网卡信息，基于时间制作出生成器 生成uuid
        TimeBasedGenerator generator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
        UUID uuid = generator.generate();
        String communityCode = "ROOM_" + uuid.toString().replaceAll("-", "");
        System.out.println("roomCode = " + communityCode);
        return communityCode;
    }

    /**
     * 生成楼栋编码
     *
     * @return
     */
    public String getBuildingCode() {
        //传入网卡信息，基于时间制作出生成器 生成uuid
        TimeBasedGenerator generator = Generators.timeBasedGenerator(EthernetAddress.fromInterface());
        UUID uuid = generator.generate();
        String communityCode = "BUILDING_" + uuid.toString().replaceAll("-", "");
        System.out.println("roomCode = " + communityCode);
        return communityCode;
    }
}
